import { dateTimeData } from "../../../utils/dateTimer";

// pages/index/batchCloud/batchCloud.js
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**授权 */
    tapAvaibale: function(e) {
      this.setData({tips: ""});
      const {value} = e.detail;
      const {idArray} = this.data;
      this.setData({available: !value});
      wx.$http.put({url: `/szm/devicecloud/batch`, data: {ids: idArray, available: value ? 0 : 1}}).then(res => {
        this.setData({available: value ? 0 : 1});
        wx.showToast({
          title: '批量设置',
        })
      });
  },

  tapLockTime: function() {
    const {idArray} = this.data;
    const _this = this;
    wx.navigateTo({
      url: `../schedule/index?lockTimeAvailable=0&lockTime=0`,
      events: {
        scheduleEvent: function(data) {
          const {lockTimeAvailable, lockTime} = data;
          if(Number(lockTime) === 0 && Number(lockTimeAvailable) === 0) {
            return;
          }
          wx.$http.put({url: `/szm/devicecloud/batch`, data: {ids: idArray, lockTimeAvailable, lockTime}}).then(res => {
            _this.setData({lockTimeText: lockTime && lockTime > 0 ? new Date(Number(lockTime)).Format() + (lockTimeAvailable ? ' 未启用' : ' 定时中')  : ""})
            wx.showToast({
              title: '批量设置',
            })
          });
        }
      }
    })
  },
    /**
     * 生命周期函数--监听页面加载 "pages/index/deviceCloud/schedule/index",
     */
    onLoad(options) {
      this.setData({
        available: 1,
        lockTimeText: "",
        tips: "未设置"
      });
      const {ids} = options;
      this.setData({idArray: ids.split(",")});
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})